package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameWorldMap extends JFrame
	{
		
		//members define
		private var btn_close:JButton;
		private var map_29:PaneWorldMapItem;
		private var map_30:PaneWorldMapItem;
		private var map_31:PaneWorldMapItem;
		private var map_32:PaneWorldMapItem;
		private var map_33:PaneWorldMapItem;
		private var map_34:PaneWorldMapItem;
		private var map_15:PaneWorldMapItem;
		private var map_16:PaneWorldMapItem;
		private var map_17:PaneWorldMapItem;
		private var map_18:PaneWorldMapItem;
		private var map_19:PaneWorldMapItem;
		private var map_21:PaneWorldMapItem;
		private var map_22:PaneWorldMapItem;
		private var map_3:PaneWorldMapItem;
		private var map_5:PaneWorldMapItem;
		private var map_6:PaneWorldMapItem;
		
		public function FrameWorldMap()
		{
			setClosable(false);
			setResizable(false);  
			setDragable(false);
			setBorder(new EmptyBorder());
			this.setTitleBar(null);
			this.setBackgroundDecorator(null);
			
			
			//component creation
			setSize(new IntDimension(1200, 600));
			setPreferredSize(new IntDimension(1200, 600));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(1160, 0));
			btn_close.setSize(new IntDimension(40, 45));
			btn_close.setPreferredSize(new IntDimension(40, 45));
			btn_close.setText("label");
			
			map_29 = new PaneWorldMapItem();
			map_29.setSize(new IntDimension(10, 10));
			
			map_30 = new PaneWorldMapItem();
			map_30.setSize(new IntDimension(400, 400));
			
			map_31 = new PaneWorldMapItem();
			map_31.setSize(new IntDimension(400, 400));
			
			map_32 = new PaneWorldMapItem();
			map_32.setSize(new IntDimension(400, 400));
			
			map_33 = new PaneWorldMapItem();
			map_33.setSize(new IntDimension(400, 400));
			
			map_34 = new PaneWorldMapItem();
			map_34.setSize(new IntDimension(10, 10));
			
			map_15 = new PaneWorldMapItem();
			map_15.setSize(new IntDimension(400, 400));
			
			map_16 = new PaneWorldMapItem();
			map_16.setSize(new IntDimension(400, 400));
			
			map_17 = new PaneWorldMapItem();
			map_17.setSize(new IntDimension(400, 400));
			
			map_18 = new PaneWorldMapItem();
			map_18.setSize(new IntDimension(10, 10));
			
			map_19 = new PaneWorldMapItem();
			map_19.setSize(new IntDimension(400, 400));
			
			map_21 = new PaneWorldMapItem();
			map_21.setSize(new IntDimension(400, 400));
			
			map_22 = new PaneWorldMapItem();
			map_22.setSize(new IntDimension(400, 400));
			
			map_3 = new PaneWorldMapItem();
			map_3.setSize(new IntDimension(400, 400));
			
			map_5 = new PaneWorldMapItem();
			map_5.setSize(new IntDimension(400, 400));
			
			map_6 = new PaneWorldMapItem();
			map_6.setSize(new IntDimension(10, 10));
			
			//component layoution
			getContentPane().append(btn_close);
			getContentPane().append(map_29);
			getContentPane().append(map_30);
			getContentPane().append(map_31);
			getContentPane().append(map_32);
			getContentPane().append(map_33);
			getContentPane().append(map_34);
			getContentPane().append(map_15);
			getContentPane().append(map_16);
			getContentPane().append(map_17);
			getContentPane().append(map_18);
			getContentPane().append(map_19);
			getContentPane().append(map_21);
			getContentPane().append(map_22);
			getContentPane().append(map_3);
			getContentPane().append(map_5);
			getContentPane().append(map_6);
			
			setImages();
		}
			
		public function setImages():void
		{
			var img_char_background:DisplayObject = Client.getUIElement("img_world_map_bg") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_char_background));
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - img_char_background.width) / 2,(Engine.H - img_char_background.height)/2);
			
			btn_close.wrapSimpleButton(Client.getUIElement("btn_world_map_close") as SimpleButton);
			btn_close.setText("");
			btn_close.addActionListener(function (e:Event):void{FrameWorldMap.hide();});
			
			
			_allItems.push(map_29);
			_allItems.push(map_30);
			_allItems.push(map_31);
			_allItems.push(map_32);
			_allItems.push(map_33);
			_allItems.push(map_34);
			_allItems.push(map_15);
			_allItems.push(map_16);
			_allItems.push(map_17);
			_allItems.push(map_18);
			_allItems.push(map_19);
			_allItems.push(map_21);
			_allItems.push(map_22);
			_allItems.push(map_3);
			_allItems.push(map_5);
			_allItems.push(map_6);
			
			map_3.updatte(3);
			map_5.updatte(5);
			map_6.updatte(6);
			map_22.updatte(22);
			map_21.updatte(21);
			map_19.updatte(19);
			map_18.updatte(18);
			map_17.updatte(17);
			map_16.updatte(16);
			map_15.updatte(15);
			map_34.updatte(34);
			map_33.updatte(33);
			map_32.updatte(32);
			map_31.updatte(31);
			map_30.updatte(30);
			map_29.updatte(29);
			
			map_3.setLocationXY(29,174);
			map_5.setLocationXY(201,189);
			map_6.setLocationXY(498,311);
			map_22.setLocationXY(1007,167);
			map_21.setLocationXY(25,436);
			map_19.setLocationXY(296,359);
			map_18.setLocationXY(362,206);
			map_17.setLocationXY(508,447);
			map_16.setLocationXY(641,292);
			map_15.setLocationXY(675,453);
			map_34.setLocationXY(969,59);
			map_33.setLocationXY(958,377);
			map_32.setLocationXY(1066,291);
			map_31.setLocationXY(808,173);
			map_30.setLocationXY(217,61);
			map_29.setLocationXY(28,55);
			
			pack();
			this.paintImmediately();
		}
		private var _allItems:Array = [];
		static private var _loaderChar:CharImageLoader = null;
		static private var _isLoadingChar:Boolean = false;
		public function updateCharImage():void
		{
			if(_loaderChar == null)
				_loaderChar = new CharImageLoader;
			var arCharEquips:Array = new Array();
			//if(CharInfo.m_nImageId != 0)
			//{
			//	arCharEquips.push(Engine.assetMapMonsterPath + "npc_"+ CharInfo.m_nImageId + '.swf');
			//}
			//else
			//{
			for each(var item:Object in CharInfo.m_arItemPage[0])
			{
				if(item.csv_id != 0)
				{
					var objItemCSV:Object = Client.getInstance().GetItemCSV(item.csv_id);
					arCharEquips.push(objItemCSV.equip_image_id);
				}
				else
				{
					arCharEquips.push(0);
				}
			}
			//}
			_loaderChar.loadChar(CharInfo.m_nRace,CharInfo.m_nGender,arCharEquips,onCharLoaded);
			_isLoadingChar = true;
		}
		static private var _mcCharHead:MovieClip = null;
		private function onCharLoaded():void
		{
			var imgSelf:Container = this.getContentPane();
			if(_mcCharHead != null && imgSelf.contains(_mcCharHead))
			{
				imgSelf.removeChild(_mcCharHead)
				_mcCharHead = null;
			}
			_isLoadingChar = false;
			_mcCharHead = _loaderChar.getImage("mc_object_run",true);
			if(_mcCharHead == null)
			{
				_loaderChar.clear();
				_loaderChar = null;
				return;
			}
			
			var mc:MovieClip = _mcCharHead;
			mc.scaleX = 0.6;
			mc.scaleY = mc.scaleX;
			mc.x = (imgSelf.width - mc.width)/2;
			imgSelf.addChild(mc);
			
			var itemFrom:PaneWorldMapItem = _frame.getMapItemByMapId(CharInfo.mapId);
			
			_mcCharHead.x = itemFrom.x + itemFrom.width / 2-_mcCharHead.width/2;
			_mcCharHead.y = itemFrom.y + itemFrom.height / 2 - _mcCharHead.height/2;
			_frame.getContentPane().bringToTop(_mcCharHead);
			
			if(_mapIdFrom != 0 || _mapIdTo != 0)
			{
				playJumpMap(_mapIdFrom,_mapIdTo);
			}
			
		}
		public function getMapItemByMapId(mapId:int): PaneWorldMapItem
		{
			for each(var item:PaneWorldMapItem in _allItems)
			{
				if(item.mapId == mapId)
					return item;
			}
			return null;
		}
		public static var _mapIdFrom:int = 0;
		public static var _mapIdTo:int = 0;
		public static function playJumpMap(mapIdFrom:int,mapIdTo:int):void
		{
			if(mapIdFrom == mapIdTo)
				return;
			if(!isShowing())
				FrameWorldMap.show();
			
			if(_mcCharHead == null)
			{
				_mapIdFrom = mapIdFrom;
				_mapIdTo = mapIdTo;
				if(!_isLoadingChar)
					_frame.updateCharImage();
				return;
			}
			
			var itemFrom:PaneWorldMapItem = _frame.getMapItemByMapId(mapIdFrom);
			var itemTo:PaneWorldMapItem = _frame.getMapItemByMapId(mapIdTo);
			
			if(itemFrom == null || itemTo == null)
			{
				FrameWorldMap.hide();
				return;
			}
			
			if(!_frame.getContentPane().contains(_mcCharHead))
			{
				_frame.getContentPane().addChild(_mcCharHead)
			}
			
			
			_mcCharHead.x = itemFrom.x + itemFrom.width / 2-_mcCharHead.width/2;
			_mcCharHead.y = itemFrom.y + itemFrom.height / 2 - _mcCharHead.height/2;
			_frame.getContentPane().bringToTop(_mcCharHead);
			
			var destX:int = itemTo.x + itemTo.width / 2-_mcCharHead.width/2;
			var destY:int = itemTo.y + itemTo.height / 2 - _mcCharHead.height/2;
			if(destX > _mcCharHead.x)
			{
				_mcCharHead.scaleX = 0.6;
			}
			else
			{
				_mcCharHead.scaleX = -0.6;
				//_mcCharHead.x = _mcCharHead.x*_mcCharHead.scaleX +_frame.getContentPane().width+_mcCharHead.width/2;
				//_mcCharHead.x = _mcCharHead.x*-1.0;
				_mcCharHead.x = _mcCharHead.x + _mcCharHead.width;
				
				destX = itemTo.x + itemTo.width / 2-_mcCharHead.width/2;
				destY = itemTo.y + itemTo.height / 2 - _mcCharHead.height/2;
				destX = destX + _mcCharHead.width
				//destY = destY + _mcCharHead.height;
			}
			
			TweenMax.to(_mcCharHead, 3, {x:destX, y:destY,onComplete:function():void
			{
				//if(FrameWorldMap._frame.getContentPane().contains(_mcCharHead))
				//{
				//	FrameWorldMap._frame.getContentPane().removeChild(_mcCharHead)
				//}
				FrameWorldMap.hide();
			}});
			_mapIdFrom = 0;
			_mapIdTo = 0;
		}
		public static var _frame:FrameWorldMap = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameWorldMap();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			
			if(_mcCharHead == null)
			{
				if(!_isLoadingChar)
					_frame.updateCharImage();
			}
			else
			{
				var itemFrom:PaneWorldMapItem = _frame.getMapItemByMapId(CharInfo.mapId);
				_mcCharHead.scaleX = 0.6;
				_mcCharHead.x = itemFrom.x + itemFrom.width / 2-_mcCharHead.width/2;
				_mcCharHead.y = itemFrom.y + itemFrom.height / 2 - _mcCharHead.height/2;
			}
			
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}

import com.*;
import com.UI.*;
import com.Engine.*;
import com.Packet.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPaneWorldMapItem
 */
class PaneWorldMapItem extends JPanel{
	
	//members define
	private var panelBtn:JPanel;
	private var panelIcon:JPanel;
	
	/**
	 * MyPaneWorldMapItem Constructor
	 */
	public function PaneWorldMapItem(){
		//component creation
		setSize(new IntDimension(400, 400));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		panelBtn = new JPanel();
		panelBtn.setSize(new IntDimension(10, 10));
		
		panelIcon = new JPanel();
		panelIcon.setSize(new IntDimension(10, 10));
		
		//component layoution
		append(panelBtn);
		append(panelIcon);
		
		this.buttonMode = true;
		panelBtn.buttonMode = true;
		panelIcon.buttonMode = true;
		addEventListener(MouseEvent.ROLL_OVER, onRollOver);
		addEventListener(MouseEvent.ROLL_OUT, onRollOut);
		
		addEventListener(ClickCountEvent.CLICK_COUNT, onItemClickCount); 
	}
	
	private var _filterArray:Array = new Array(new GlowFilter(0xffff00, 1, 20, 20));
	private function onRollOver(event:MouseEvent):void
	{
		event.target.filters = _filterArray;
	}
	
	private function onRollOut(event:MouseEvent):void
	{
		event.target.filters = null;
	}
	
	private function onItemClickCount(event:ClickCountEvent):void
	{   
		if(event.getCount() >= 1)
		{   
			Client.getInstance().sendPacketLogic(9,[int(mapId),CharInfo.mapLineId,CharInfo.mapType,CharInfo.mapOwnerId,int(0),int(0)]);
		}   
		//FrameWorldMap.hide();
	} 
	
	public var mapId:int = 0;
	public function updatte(id:int):void
	{
		mapId = id;
		var img_background:DisplayObject = Client.getUIElement("img_map_"+mapId+"_btn") as DisplayObject
		panelBtn.setBackgroundDecorator(new AssetBackground(img_background));
		panelBtn.setSizeWH(img_background.width,img_background.height);
		
		img_background = Client.getUIElement("img_map_"+mapId+"_icon") as DisplayObject
		panelIcon.setBackgroundDecorator(new AssetBackground(img_background));
		panelIcon.setSizeWH(img_background.width,img_background.height);
		
		var allWidth:int = panelBtn.width > panelIcon.width ? panelBtn.width : panelIcon.width;
		var allHeiht:int = panelBtn.height + panelIcon.height;
		
		this.setSizeWH(allWidth,allHeiht);
		panelBtn.setLocationXY((allWidth - panelBtn.width)/2,0);
		panelIcon.setLocationXY((allWidth - panelIcon.width)/2,panelBtn.height);
		
		pack();
		this.paintImmediately();
	}
	//_________getters_________
	
	
	
	
}